package com.atguigu.distributed.lock.leecode;

public class BigNumPlus {
    public String solution(String s,String t){
        //让S为较长的，t为较短的
        if(s.length()<t.length()){
            String temp = s;
            s = t;
            t = temp;
        }
        int carry = 0; //进位标志
        char[] res = new char[s.length()];
        for (int i = s.length()-1; i >=0 ; i--) {
            //转数字加上进位
            int temp = s.charAt(i) - '0' +carry;
            //转较短的字符串相应的从后往前的下标
            int j = i-s.length()+t.length();
            if(j>=0){
                //转数组相加
                temp+=t.charAt(j)-'0';
            }
            //取进位
            carry = temp/10;
            //去十位
            temp = temp%10;
            //修改结果
            res[i] = (char)(temp+'0');
        }
        String output = String.valueOf(res);
        if(carry==1){
            output = '1'+output;
        }
        return output;
    }

    public static void main(String[] args) {
        BigNumPlus bigNumPlus = new BigNumPlus();
        String s1 = "467";
        String s2 = "19999";
        String solution = bigNumPlus.solution(s1, s2);
        System.out.println("res==>"+solution);
    }
}
